package com.ruoyi.xiaoshou.service.impl;

import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.xiaoshou.domain.CustomerReport;
import com.ruoyi.xiaoshou.mapper.CustomerReportMapper;
import com.ruoyi.xiaoshou.service.ICustomerReportService;
import com.ruoyi.xiaoshou.utils.JasperPdfUtil;
import net.sf.jasperreports.engine.JRException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 客户报表Service业务层处理
 *
 * @author wl
 * @date 2024-11-12
 */
@Service
public class CustomerReportServiceImpl implements ICustomerReportService {
    @Autowired
    private CustomerReportMapper customerReportMapper;

    /**
     * 查询客户报表列表
     *
     * @param customerReport 客户报表
     * @return 客户报表
     */
    @Override
    public List<CustomerReport> selectCustomerReportList(CustomerReport customerReport) {
        return customerReportMapper.selectCustomerReportList(customerReport);
    }

    /**
     * @return byte[]
     * @description 打印客户报表pdf
     * @date 2024/11/15 下午5:23
     * @Param customerReport:
     **/
    public byte[] printCustomerReport(CustomerReport customerReport) throws JRException, FileNotFoundException {
        String templatePath = "jasper/CustomerReport.jrxml";
        Map<String, Object> paramsMap = new HashMap<>();
        paramsMap.put("createBy", SecurityUtils.getUsername());
        List<CustomerReport> list = customerReportMapper.selectCustomerReportList(customerReport);
        return JasperPdfUtil.exportPdfFromXml(templatePath, paramsMap, list);
    }
}
